﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using Microhard.Permission.Models;
using Microhard.Framework.MVCHelper;
using Microhard.Permission.Interface;
using Microsoft.Practices.Unity;
using Microhard.WebUI.Models;
using Microhard.Permission.MVCFilter;

namespace Microhard.WebUI.Areas.Admin.Controllers
{
    public class RoleController : MicroHardBaseController<Role>
    {
        private IRole _role = null;

        public RoleController()
        {
            base._isUsingPagingInIndex = false;
        }

        [Dependency]
        public IRole role 
        {
            set {
                base._repository = value;
                this._role = value; 
            }
            get {
                return this._role;
            }
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult GetSelectList(AttriubteOfSelectList ctrAttr)
        {
            var roles = _role.Query(null);
            ctrAttr.Data = roles.Select(r => new SelectData {
                ID = r.RoleId.ToString(),
                Name = r.RoleName
            }).ToList();
            return View("SelectList", ctrAttr);
        }

        [MVCFilterAtrForLogon()]
        [MVCFilterAtrForResourcePermission(OperationKeyName = "Index")]
        public ActionResult RoleSelect(AttributeOfWindow aowModel)
        {
            var rtn = _role.Query(null);
            aowModel.Data = new GridModel()
            {
                Data = rtn
            };
            return View(aowModel);
        }

    }
}
